<?php
include 'admin_passport_module_lib.php';

$a_modules_actions = $a_modules = array();

// <editor-fold defaultstate="collapsed" desc="Get Data">
make_where($s_Where, $a_filterings);

$db_query  = 'select count(moduleid) from passport_module';
$db_query  = $db_query . $s_Where;
$d_total   = db_query_single_value($db_conn, $db_query);

namhoa_pagelink($s_Pagination, $s_ScriptName, $s_QueryString, $i_Page, $i_Page_Size, $s_Page_Start, $d_total);

$db_query  = db_get_query($a_tablecolumns_namhoa_passport_module);
$db_query  = $db_query . $s_Where;
$db_result = db_query_page($db_conn, $db_query, $s_Page_Start, $i_Page_Size);

while($d_row = db_fetch($db_result)){
    $a_modules[$d_row->moduleid] = $d_row;
}

$db_query = "
    select  moduleid, pma.actionid, actionname
    from    passport_module_action as pma, passport_action as pa
    where   pma.actionid = pa.actionid and moduleid in ('" . implode("','", array_keys($a_modules)) . "')";
$db_result = db_query($db_conn, $db_query);

while ($d_row = db_fetch($db_result)){
    $a_modules_actions[$d_row->moduleid][$d_row->actionid] = $d_row->actionname;
}
// </editor-fold>

include 'lib_head.php';
?>

<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div id="portlet-config" class="modal hide">
    <div class="modal-header">
        <button data-dismiss="modal" class="close" type="button"></button>
        <h3>Bộ Lọc</h3>
    </div>
    <div class="modal-body">
        Điền thông tin cần thiết để lọc được dữ liệu thích hợp.
    </div>
</div>
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div class="row-fluid">
    <!-- BEGIN BORDERED TABLE PORTLET-->
    <div class="portlet box green">
        <div class="portlet-title">
            <div class="caption"><i class="icon-filter"></i>Lọc Dữ Liệu</div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
                <a href="#portlet-config" data-toggle="modal" class="config"></a>
            </div>
        </div>
        <div class="portlet-body">
            <form action="" style="margin: 0px;">
                <div class="pull-left margin-right-20">
                    <div class="control-group">
                        <div class="controls">
                            <div class="input-prepend">
                                <div class="btn-group">
                                    <select name="field1" class="m-wrap span12">
                                        <?= build_filter_namhoa_passport_module($s_field1) ?>
                                    </select>
                                </div>
                                <input class="m-wrap medium span12" name="keyword1" type="text" value="<?=check_plain($s_keyword1)?>"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="pull-left">
                    <div class="control-group">
                        <div class="controls">
                            <div class="input-prepend">
                                <button class="btn blue">BẮT ĐẦU LỌC <i class="m-icon-swapright m-icon-white"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </form>
        </div>
    </div>
    <!-- END BORDERED TABLE PORTLET-->
    <div class="portlet-body">
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th style="text-align: center;">Module ID</th>
                    <th style="text-align: center;">Module Name</th>
                    <th style="text-align: center;">Module Status</th>
                    <th style="text-align: center;">Action</th>
                    <th>
                        <a class="btn purple" href="admin_passport_module_form.php?action=insert&amp;<?= $s_QueryString_Page ?>">
                            <i class="icon-plus m-icon-white"></i> Add New Module
                        </a>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php foreach($a_modules as $v_moduleid => $o_module) { ?>
                <tr>
                    <td>
                        <strong><?= check_plain($o_module->moduleid) ?></strong>
                    </td>
                    <td>
                        <strong><?= check_plain($o_module->modulename) ?></strong>
                    </td>
                    <td><?= check_plain($o_module->modulestatus  ) ?></td>
                    <td>
                        <?php
                        if(isset($a_modules_actions[$o_module->moduleid])) {
                            echo implode("<br/>", $a_modules_actions[$o_module->moduleid]);
                        }
                        ?>
                    </td>
                    <td>
                        <a class="btn mini purple-stripe" href="admin_passport_module_form.php?action=update&amp;moduleid=<?=$o_module->moduleid?>&amp;<?= $s_QueryString_Page ?>">
                            <i class="icon-pencil"></i> Update
                        </a>
                        <a class="btn mini red-stripe" href="javascript:namhoa.single_delete('admin_passport_module_execute.php?action=delete&amp;moduleid=<?=$o_module->moduleid?>&amp;<?= $s_QueryString_Page ?>')">
                            <i class="icon-remove"></i> Delete
                        </a>
                    </td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <div class="pagination pagination-centered">
        <?=$s_Pagination?>
    </div>
</div>
<?php include 'lib_tail.php'; ?>